#ifndef SKY_H_INCLUDED
#define SKY_H_INCLUDED

#include <vector>

#include <d3dx9.h>
#include "dxstdafx.h"

#include "mmgr.h"

#define SKY_RADIUS 1000
#define SKY_SMOOTHNESS 50
#define SUN_ANGLE D3DX_PI/2
#define SUN_TRACK_ANGLE D3DX_PI/2

//For sky dome
struct SSkyVertex
{
	float x, y, z;
	float tu, tv;
};

#define D3DFVF_SKYVERTEX (D3DFVF_XYZ|D3DFVF_TEX1)

class CSky
{
public:
	CSky();
	~CSky();

	bool init();
	bool render(const D3DXVECTOR3* cameraPos);
	void cleanUp();

	//Settings

private:
	LPDIRECT3DDEVICE9       pD3DDevice;
	LPDIRECT3DVERTEXBUFFER9 pVertexBuffer;
	LPDIRECT3DINDEXBUFFER9  pIndexBuffer;
	LPDIRECT3DVERTEXBUFFER9 pSunVertexBuffer;
	LPD3DXEFFECT	        pSkyEffect;

	LPDIRECT3DTEXTURE9      pSkyGradient;
	LPDIRECT3DTEXTURE9      pSunTexture;

	//Settings
	float sunAngle;
	float sunTrackAngle;

	//Helper functions
	bool  makeSphere(int nRings , int nSegments); 
	DWORD calculateColor(float x, float y, float z);
	bool  generateSun();

};

#endif
